{include file="public/header" /}
<style>
   
    .bottombar{
        width: 100% !important;
        display: block !important;
        margin-top: 10px !important;
        text-align: right;
    }
    .groupbtn{
        background: var(--bc);
        color: #fff;
        font-size: 0.9rem;
        border-radius: 5px;
        padding: 5px 20px;
        margin-left: auto;
        display: inline-table;
        margin-top:10px;
        margin-bottom: 10px;
    }
    .group_mr{
        background: var(--c9) !important;
    }
</style>
<body class="bgc record-bgc">
<div class="header">
    <i class="layui-icon layui-icon-left goBack"></i>{$info.title??""}
</div>

<ul class="new-record tpl_list">
</ul>

<script id="template" type="text/html">
    {{# for(var i=0;i < d.data.length ;i++){ }}
    <li class="new-record-li">
        <div class="top">
            <p class="top-text">{{d.data[i].title}}</p>
        </div>
        <div class="bottom ">
            <p class="times">所需缔造积分：{{d.data[i].bonus_2}}</p>
            <p class="sour">所需燃料积分：{{d.data[i].bonus_4}}</p>
        </div>
        <div class="bottom bottombar">
            {{# if(d.data[i].is_time == 1){ }}
                <div class="groupbtn group_mr">缔造未开始</div>
            {{# }else if(d.data[i].is_time == 2){ }}
                <div class="groupbtn group_mr">缔造已结束</div>
            {{# }else{ }}
                {{# if(d.data[i].is_pay == 1){ }}
                    <div class="groupbtn group_mr">团已满</div>
                {{# }else{ }}
                    {{# if(d.data[i].is_buy == 1){ }}
                        <div class="groupbtn group_buy"  data-pid="{{d.data[i].id}}" onclick="group_buy({{d.data[i].id}},{$id},{{d.data[i].is_bonus}});">参与缔造</div>
                    {{# }else{}}
                        <div class="groupbtn group_mr">已参团</div>
                    {{# } }}
                {{# } }}
            {{# } }}
        </div>
    </li>
    {{# } }}
</script>

{include file="public/menu" select="2" /}
</body>
{include file="public/footer"/}
<script>
    $(function () {
        getFlow(1, "{:url('wholesale/getProductList')}?id={$id}");
    });
    $(document).ready(function() {
        $('.group_buy').on('click', group_buy);
    });
    var group_buy = debounce(function(e,wid,is_bonus){
        groupSubmitBuy(e,wid,is_bonus);
    },1000);
    function groupSubmitBuy(pid,wid,is_bonus){
        var  is_medal = 0;
        if(is_bonus == 1){
            layer.confirm('是否使用特权勋章', {
                title: '请确认',
                btn: ['使用', '不使用'] //按钮
            }, function (index) {
                is_medal=1;
                $.post("{:url('submitBuy')}",{pid,wid,is_medal},function(data,status){
                    parent.layer.msg(data.msg, {time: 1000}, function () {
                        window.location.reload();
                    });
                });
            },function() {
                $.post("{:url('submitBuy')}",{pid,wid,is_medal},function(data,status){
                    parent.layer.msg(data.msg, {time: 1000}, function () {
                        window.location.reload();
                    });
                });
            }); 
        }else{
            $.post("{:url('submitBuy')}",{pid,wid,is_medal},function(data,status){
                parent.layer.msg(data.msg, {time: 1000}, function () {
                    window.location.reload();
                });
            });
        }
      
    }
    /**
     * 防抖函数
     */
     function debounce(func, wait, immediate) {
        var timeout;
        return function() {
            var context = this, args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    }
</script>
</html>